<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Jobs extends MY_Luckydog
{
	public function __construct()
	{
		parent::__construct();
        
        $this->load->model('luckydog/Jobs_model', 'jobs');
        $this->load->model('luckydog/Address_model', 'address');
	}

/**
 * 新闻列表
 * @return [type] [description]
 */
    public function index(){
        $per_page = $this->input->get('per_page') ? $this->input->get('per_page') : 0;
        $keyword = $this->input->get('keyword') ? $this->input->get('keyword') : '';
        $endtime = $this->input->get('endtime') ? $this->input->get('endtime') : 0;
        $starttime = $this->input->get('starttime') ? $this->input->get('starttime') : 0;
        $_SESSION['v_menu'] = 'jobs';
        $filter = array('keyword'=>$keyword,'endtime'=>strtotime($endtime),'starttime'=>strtotime($starttime));
        $limit = 20;
        $total_rows = $this->jobs->getJobsCnt($filter);
        $base_url = '/luckydog/jobs/index?';
        $page_links = $this->create_page_links($base_url,$total_rows,$limit);
        $jobsList = $this->jobs->getJobsList($filter,$per_page, $limit);
        $data = array(
            'jobsList'=>$jobsList,
            'page_links'=>$page_links,
            'per_page'=>$per_page,
            'total_rows'=>$total_rows,
            'keyword'=>$keyword,
            'starttime'=>$starttime,
            'endtime'=>$endtime
            );
        $this->load->view("/luckydog/jobs/index", $data);
    }

    public function textures()
    {
        
        $id = $this->input->get("id",true)?$this->input->get("id",true):"";
        $_SESSION['v_menu'] = 'jobs';
        $data = array();
        if(!empty($id)){
            $jobsInfo = $this->jobs->getJobsInfobyID($id);
            if($jobsInfo['region'])
            {
                $region = explode(",",$jobsInfo['region']);
                $jobsInfo['provinceid'] = $region[0];
                $jobsInfo['cityid'] = $region[1];
            }
            $data["jobsInfo"] = $jobsInfo;
        }else{
            $data["jobsInfo"]['point'] = $point;
        }

        $this->load->model("address_model","address");
        $fields = " id, name ";
        //基本信息
        $provinceList = array();
        $provinceList = $this->address->getProvinceList($fields);
        $provinceId = $jobsInfo['provinceid']?$jobsInfo['provinceid']:110000;
        $cityList = array();
        $cityList = $this->address->getCityList($provinceId, $fields);

        // print_R($provinceList);
        $data['provinceList'] = $provinceList;
        $data['cityList'] = $cityList;
    	$this->load->view("/luckydog/jobs/textures", $data);
    }

     public function cityList(){
        $privinceid = $this->input->post("privinceid",true) ? $this->input->post("privinceid",true) : 110000;
        
        $cityList = array();
        $fields = " id, name ";
        //基本信息
        $cityList = $this->address->getCityList($privinceid, $fields);
        echo json_encode($cityList);
        exit();
    }



    //编辑新闻
    public function editJobs(){
        $id = $this->input->post("id",true) ? $this->input->post("id",true) : 0;
        $content = $this->input->post("contents") ? $this->input->post("contents") : "";
        $name = $this->input->post("name",true) ? $this->input->post("name",true) : "";
        $headcount = $this->input->post("headcount",true) ? $this->input->post("headcount",true) : 0;
        $provinceid = $this->input->post("provinceid",true) ? $this->input->post("provinceid",true) : "";
        $cityid = $this->input->post("cityid",true) ? $this->input->post("cityid",true) : "";
        $salary = $this->input->post("salary",true) ? $this->input->post("salary",true) : 0;
        $sort = $this->input->post("sort",true) ? $this->input->post("sort",true) : 0;

        $data = array(
            "content"=>$content ,
            "name"=>$name ,
            "headcount"=>$headcount,
            "salary"=>$salary,
            "sort"=>$sort,
            'region'=>$provinceid?($provinceid.",".$cityid):'',
        );
        if(empty($id)){
            $data['publishtime']=time();
        }
        $res = $this->jobs->editJobs($id,$data);
        echo $res;
    }


    //编辑上线下，删除状态
    public function delJobs(){
        $id = $this->input->post("id",true) ? $this->input->post("id",true) : 0;
        $res =$this->jobs->delJobs($id);
        echo $res;
    }


   

    //编辑上线下，删除状态
    public function editStatus(){
        $id = $this->input->post("id",true) ? $this->input->post("id",true) : 0;
        $onlinestatus = $this->input->post("onlinestatus",true) ? $this->input->post("onlinestatus",true) : "";
        $data = array(
            "id"=>$id,
            "onlinestatus"=>$onlinestatus,
        );
        $res =$this->jobs->editStatus($data);
        echo $res;
    }

  

}
/* End of file index.php */
/* Location: ./application/controllers/luckydog/index.php */
